//
//  YWCircleDetailTableViewCell.m
//  聆听FM
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 Dark. All rights reserved.
//

#import "YWCircleDetailTableViewCell.h"

@implementation YWCircleDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.numLabel = [[UILabel alloc] init];
        _numLabel.font = [UIFont systemFontOfSize:14];
        _numLabel.textAlignment = 2;
        [self.contentView addSubview:_numLabel];
        
        self.photoImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_photoImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.numberOfLines = 0;
        [self.contentView addSubview:_titleLabel];
        
        self.iconImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_iconImageView];
        
        self.nickNameLabel = [[UILabel alloc] init];
        _nickNameLabel.font = [UIFont systemFontOfSize:12];
        _nickNameLabel.textColor = [UIColor colorWithWhite:0.651 alpha:1.000];
        [self.contentView addSubview:_nickNameLabel];
        
        self.lineLabel = [[UILabel alloc] init];
        _lineLabel.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_lineLabel];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
   
    NSString *string = _detailModel.title;
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
    CGRect newRect = [string boundingRectWithSize:CGSizeMake(290 * FITWIDTH, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    _numLabel.frame = CGRectMake(0 * FITWIDTH, 15 * FITHEIGHT, 30 * FITWIDTH, 15 * FITHEIGHT);
    _photoImageView.frame = CGRectMake(40 * FITWIDTH, 10 * FITHEIGHT, 30 * FITWIDTH, 30 * FITHEIGHT);
    _photoImageView.layer.cornerRadius = 15 * FITHEIGHT;
    _photoImageView.layer.masksToBounds = YES;
    _titleLabel.frame = CGRectMake(80 * FITWIDTH, 10 * FITHEIGHT, 280 * FITWIDTH, newRect.size.height);
    _iconImageView.frame = CGRectMake(_titleLabel.frame.origin.x, _titleLabel.bounds.size.height + 25 * FITHEIGHT, 12 * FITWIDTH, 12 * FITHEIGHT);
    _nickNameLabel.frame = CGRectMake(_iconImageView.frame.origin.x + _iconImageView.bounds.size.width + 5 * FITWIDTH, _iconImageView.frame.origin.y, 150 * FITWIDTH, 15 * FITHEIGHT);
    _lineLabel.frame = CGRectMake(90 * FITWIDTH, self.bounds.size.height - 1, SCREENWIDTH - 100 * FITWIDTH, 1);
}

- (void)setDetailModel:(YWPicDetailModel *)detailModel
{
    if (_detailModel != detailModel) {
        _detailModel = detailModel;
        [_photoImageView sd_setImageWithURL:[NSURL URLWithString:detailModel.coverSmall] placeholderImage:[UIImage sd_animatedGIFNamed:@"占位图"]];
        _titleLabel.text = detailModel.title;
        _iconImageView.image = [UIImage imageNamed:@"head"];
        _nickNameLabel.text = detailModel.nickname;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
